package com.example.monitor.model.enums;

public enum AlarmStatus {
    unprocessed("unprocessed", "未处理"),
    processing("processing", "处理中"),
    resolved("resolved", "已解决");

    private final String code;
    private final String description;

    AlarmStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }
    // 添加容错解析逻辑
    public static AlarmStatus fromCode(String dbValue) {
        if (dbValue == null) return null;

        // 去除首尾空格
        String trimmedValue = dbValue.trim();

        // 兼容大小写和常见拼写变体
        for (AlarmStatus status : values()) {
            if (status.code.equalsIgnoreCase(trimmedValue)) {
                return status;
            }
        }
        throw new IllegalArgumentException("无效的status值: '" + dbValue + "'");
    }

    // 根据中文描述获取枚举
    public static AlarmStatus fromDescription(String desc) {
        for (AlarmStatus status : values()) {
            if (status.description.equals(desc)) {
                return status;
            }
        }
        throw new IllegalArgumentException("无效的状态描述: " + desc);
    }
}
